using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using ALC.Core.ViewModels.Chart;

namespace ALC.Views.Charts
{
    public partial class LineChartView : UserControl
    {
        public LineChartView()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(
            "ViewModel", typeof(LineChartViewModel), typeof(LineChartView), new PropertyMetadata(default(LineChartViewModel), OnViewModelChanged));

        public LineChartViewModel ViewModel
        {
            get { return (LineChartViewModel) GetValue(ViewModelProperty); }
            set { SetValue(ViewModelProperty, value); }
        }

        private static void OnViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var viewModel = (Core.ViewModels.Chart.LineChartViewModel) e.NewValue;
            if (viewModel == null) return;
            var view = (LineChartView) d;
            viewModel.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName != nameof(Core.ViewModels.Chart.LineChartViewModel.Y)) return;
                view.PART_Linegraph.Plot(viewModel.X, viewModel.Y);
            };
        }
        


    }
}